import pandas as pd
def bsAbs(target1_kon,target1_koff,target2_kon,target2_koff,tumor_rate,macrophage_rate,abs):
    volumn = 2e-4 # L
    R = 6.023e+23
    # target2_kon = 0.5076 # /nm/h
    # target2_koff = 1.27e-06 #/nm

    macrophage = 1e+4 * macrophage_rate# 
    target1_expression = 50e+4
    target1 = macrophage * target1_expression/R *volumn # Mol / L

    tumor = 1e+4 * tumor_rate# 
    target2_expression = 10e+4
    target2 = tumor * target2_expression/R *volumn # Mol / L
    abst1 = 0
    abst2 = 0
    trimer = 0
    interval = 0.001
    #
    metric = {}
    metric['times'] = [0]
    metric['abss'] = [abs]
    metric['target1s'] = [target1]
    metric['target2s'] = [target2]
    metric['abst1s'] = [0]
    metric['abst2s'] = [0]
    metric['trimer'] = [0]
    for i in np.arange(interval,72,interval): # 0到72小时变化
        # 计算梯度
        delta_abs = interval * (target1_koff *abst1 + target2_koff * abst2 - target1_kon * abs * target1 - target2_kon * abs * target2 )
        delta_target1 = interval * (target1_koff * (abst1 + trimer)  - target1_kon * (abs+abst2) * target1)
        delta_target2 = interval * (target2_koff *(abst2 + trimer)  - target2_kon * (abs+abst1) * target2)
        delta_abst1 = interval * (- target1_koff *abst1 - target2_kon * abst1 *target2 + target1_kon * abs * target1 + target2_koff *trimer)
        delta_abst2 = interval * (- target2_koff *abst2 - target1_kon * abst2 *target1 + target2_kon * abs * target2 + target1_koff *trimer)
        delta_trimer = interval * (- target2_koff *trimer - target1_koff *trimer + target1_kon * abst2 *target1 + target2_kon * abst1 *target2 )
        # 更新梯度
        abs += delta_abs
        target1 += delta_target1
        target2 += delta_target2
        abst1 += delta_abst1
        abst2 += delta_abst2
        trimer += delta_trimer
        if not (abs>=0 and target1>=0 and  target2>=0 and abst1>=0 and abst2>=0 and trimer>=0):
            break
        # 保存结果
        metric['abss'].append(abs)
        metric['target1s'].append(target1)
        metric['target2s'].append(target2)
        metric['abst1s'].append(abst1)
        metric['abst2s'].append(abst2)
        metric['trimer'].append(trimer)
        metric['times'].append(i)
    metric = pd.DataFrame.from_dict(metric)
    metric = metric.set_index('times')
    # metric.to_excel(save_result,index=None)
    return metric